package com.team5.mapper;

import com.team5.entity.ChinaIndex;
import com.team5.entity.RFRange;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface RFRangeMapper {
    @Select("select * from \"SCOTT\".PARTFUND where id=#{id}")
    RFRange findById(Integer id);
    @Select("select * from \"SCOTT\".PARTFUND")
    RFRange[] findAll();
    @Select("select * from \"SCOTT\".PARTFUND where name like CONCAT('%', #{name}, '%')")
    List<RFRange> findByName(String name);
    // 查询涨幅最大的 3-5 个板块
    @Select("SELECT * FROM (SELECT * FROM \"SCOTT\".PARTFUND WHERE change > 0 ORDER BY change DESC) WHERE ROWNUM <= 5")
    List<RFRange> findTopGainers();
    // 查询跌幅最大的 3-5 个板块
    @Select("SELECT * FROM ( SELECT * FROM \"SCOTT\".PARTFUND WHERE change < 0 ORDER BY change ASC) WHERE ROWNUM <= 5")
    List<RFRange> findTopLosers();
     @Delete("delete from \"SCOTT\".PARTFUND where id=#{id}")
     int deleteById(Integer id);
    @Delete("delete from \"SCOTT\".PARTFUND")
    int deleteAll();
     @Insert("insert into \"SCOTT\".PARTFUND (id, name, change) " +
             "values (#{id}, #{name}, #{change})")
     @SelectKey(statement = "SELECT seq_bankuai.NEXTVAL FROM DUAL", keyProperty = "id", before = true, resultType = int.class)
     int insert(RFRange rFRange);
     @Update("update \"SCOTT\".PARTFUND set " +
             "name=#{name}, change=#{change} where id=#{id}")
     int updateById(RFRange rFRange);

    @Update("update \"SCOTT\".PARTFUND set " +
            "change=#{item.change} where name=#{item.name}")
    int updateChangeByName(@Param("item") RFRange item);
}
